/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.yuecai.modules.yc_user.domain;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.time.Instant;

/**
* @website https://el-admin.vip
* @description /
* @author dm
* @date 2020-06-22
**/
@Entity
@Data
@Table(name="yc_user")
public class YcUser implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    @ApiModelProperty(value = "id")
    private Long id;

    @Column(name = "username")
    @ApiModelProperty(value = "用户名")
    private String username;

    @JsonIgnore
    @Column(name = "password")
    @ApiModelProperty(value = "密码")
    private String password;

    @Column(name = "phone",unique = true,nullable = false)
    @NotBlank
    @ApiModelProperty(value = "手机号")
    private String phone;

    @Column(name = "img_url")
    @ApiModelProperty(value = "头像地址")
    private String imgUrl;

    @Column(name = "pid")
    @ApiModelProperty(value = "推荐人Id")
    private Long pid;

    @Column(name = "state")
    @ApiModelProperty(value = "0正常1删除2冻结")
    private Integer state;

    @Column(name = "create_time")
    @ApiModelProperty(value = "创建时间")
    private Instant createTime;

    @Column(name = "last_update_time")
    @ApiModelProperty(value = "修改时间")
    private Instant lastUpdateTime;

    @Column(name = "nick_name")
    @ApiModelProperty(value = "昵称")
    private String nickName;

    @Column(name = "sex")
    @ApiModelProperty(value = "0女1男")
    private Boolean sex;

    @Column(name = "birthday")
    @ApiModelProperty(value = "生日")
    private Instant birthday;

    @Column(name = "city")
    @ApiModelProperty(value = "城市")
    private String city;

    @Column(name = "occupation")
    @ApiModelProperty(value = "职业")
    private String occupation;

    @Column(name = "sign")
    @ApiModelProperty(value = "个签")
    private String sign;

    @Column(name = "last_login_time")
    @ApiModelProperty(value = "上次登陆时间")
    private Instant lastLoginTime;

    @Column(name = "level")
    @ApiModelProperty(value = "用户等级 type为1的时候有值 1普通用户、2会员用户")
    private Integer level;

    @Column(name = "type")
    @ApiModelProperty(value = "1店铺用户、2司机、3业务员")
    private Integer type;

    @Column(name = "real_name")
    @ApiModelProperty(value = "是否实名，1实名了，0未实名")
    private boolean realName;

    @Column(name = "referral_code")
    @ApiModelProperty(value = "推荐码")
    private String referralCode;

    public void copy(YcUser source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}